package akash.java.code;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class ReadXL
{
    public static void main(String[] args)
    {
        try
        {
            InputStream inputStream = new FileInputStream("D:/akash.xlsx");
           XSSFWorkbook wb = new XSSFWorkbook(inputStream);
           
            XSSFSheet sheet = (XSSFSheet)wb.getSheetAt(0);
            Iterator<Row> rows = sheet.rowIterator();
            while(rows.hasNext())
            {
                XSSFRow row = (XSSFRow)rows.next();
                System.out.println();
                Iterator cells = row.cellIterator();
                while(cells.hasNext())
                {
                    XSSFCell cell = (XSSFCell)cells.next();
                    if (XSSFCell.CELL_TYPE_NUMERIC == cell.getCellType())
                    {
                        System.out.print(cell.getNumericCellValue() + "  ");

                    }
                    else if (XSSFCell.CELL_TYPE_STRING == cell.getCellType())
                    {
                        System.out.print(cell.getStringCellValue() + "  ");
                    }
                    else if (XSSFCell.CELL_TYPE_BOOLEAN == cell.getCellType())
                    {
                        System.out.print(cell.getBooleanCellValue() + "  ");
                    }
                    else if (XSSFCell.CELL_TYPE_BLANK == cell.getCellType())
                    {
                        System.out.print("Blank  ");
                    }
                    else
                    {
                        System.out.println("Unknown cell type");
                    }
                }
            }
        }
        catch(IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
